function Weight = Update_weight2(distance,W,w_index)
[~,M] = size(W);
[dis,index] = sort(distance);
w_index = w_index(index);
new_distance = [dis,w_index];           
usel = find(new_distance(:,1)==0);      
useless = new_distance(usel,2);         
new_distance(usel,:) = [];              

tiao = new_distance(:,2); 
if M==2
    num = round(length(index)/10);                 
elseif M == 3
    num = round(length(index)/10);                 
end
delete_yongji = tiao([1:2:num]);        
all_index = [useless',delete_yongji'];  
tiao([1:2:num]) = [];                   
tiao_index = fliplr(tiao');         
n2 = 0;
W_new2 = zeros(length(all_index),M);
flag1 = 0;
while ~isempty(all_index) && flag1 < length(all_index)
    n2 = n2+1;
    [W_new2,flag1] = new_weight(all_index,tiao_index,W,n2,flag1,W_new2);
end

W(all_index',:)=[];
W_new = [W;W_new2];
Weight = sortrows(W_new);
end



